package 算法.leetcode.labuladong.数组和链表;

import 算法.leetcode.offer.base.ListNode;

/**
 * https://leetcode.cn/problems/linked-list-cycle/
 * @author lchenglong
 * @date 2022/6/16
 */
public class 环形链表 {
    public class Solution {
        public boolean hasCycle(ListNode head) {
            ListNode fast = head,slow = head;
            while (fast!=null && fast.next!=null) {
                // 快指针走两步,慢指针走一步
                fast = fast.next.next;
                slow = slow.next;
                if (fast == slow){
                    return true;
                }
            }
            // 不包含环
            return false;
        }
    }
}
